﻿'******************************* File Header *********************************
'* File Name:    WmiParameterCollectionTest.vb
'* Project:      WmiConnection.Test
'* Copyright (c) Freddy Kuehne
'*
'* Unit tests for WmiParameterCollection.
'* 
'* This source is subject to the GNU Library General Public License (LGPL).
'* See http://wmiconnection.codeplex.com/license.
'* All other rights reserved.
'*****************************************************************************
Imports System.Text
Imports System.Data.Common

<TestClass()>
Public Class WmiParameterCollectionTest
#Region "Tests"
  <TestMethod()>
  Public Sub ConstructorTest()
    Dim target As New WmiParameterCollection()
    Assert.IsNotNull(target)
  End Sub

  <TestMethod()>
  Public Sub HierarchyTest()
    Dim target As New WmiParameterCollection
    Assert.IsInstanceOfType(target, GetType(DbParameterCollection))
  End Sub

  <TestMethod()>
  Public Sub AddTest()
    Dim target As New WmiParameterCollection
    Assert.AreEqual(0, target.Count)
    target.Add(New WmiParameter)
    Assert.AreEqual(1, target.Count)
  End Sub

  <TestMethod(), ExpectedException(GetType(ArgumentNullException))>
  Public Sub AddException1Test()
    Dim target As New WmiParameterCollection
    target.Add(Nothing)
  End Sub

  <TestMethod(), ExpectedException(GetType(InvalidCastException))>
  Public Sub AddException2Test()
    Dim target As New WmiParameterCollection
    target.Add(String.Empty)
  End Sub

  <TestMethod()>
  Public Sub AddRangeTest()
    Dim target As New WmiParameterCollection
    target.AddRange(New WmiParameter() {New WmiParameter, New WmiParameter})
    Assert.AreEqual(2, target.Count)
  End Sub

  <TestMethod(), ExpectedException(GetType(ArgumentNullException))>
  Public Sub AddRangeException1Test()
    Dim target As New WmiParameterCollection
    target.AddRange(Nothing)
  End Sub

  <TestMethod(), ExpectedException(GetType(InvalidCastException))>
  Public Sub AddRangeException2Test()
    Dim target As New WmiParameterCollection
    target.AddRange(New Object() {String.Empty, String.Empty})
  End Sub

  <TestMethod()>
  Public Sub ClearTest()
    Dim target As New WmiParameterCollection
    target.Clear()
    Assert.AreEqual(0, target.Count)
    target.Add(New WmiParameter)
    Assert.AreEqual(1, target.Count)
    target.Clear()
    Assert.AreEqual(0, target.Count)
    target.Clear()
    Assert.AreEqual(0, target.Count)
  End Sub

  <TestMethod()>
  Public Sub ContainsTest()
    Dim param As New WmiParameter
    Dim target As New WmiParameterCollection
    Assert.IsFalse(target.Contains(Nothing))
    Assert.IsFalse(target.Contains(String.Empty))
    Assert.IsFalse(target.Contains(param))
    target.Add(param)
    Assert.IsTrue(target.Contains(param))
  End Sub

  <TestMethod()>
  Public Sub CopyToTest()
    Dim params(0) As WmiParameter
    Dim target As New WmiParameterCollection
    target.Add(New WmiParameter)
    target.CopyTo(params, 0)
    Assert.AreSame(target.Item(0), params(0))
  End Sub

  <TestMethod(), ExpectedException(GetType(ArgumentNullException))>
  Public Sub CopyToException1Test()
    Dim target As New WmiParameterCollection
    target.CopyTo(Nothing, 0)
  End Sub

  <TestMethod(), ExpectedException(GetType(IndexOutOfRangeException))>
  Public Sub CopyToException2Test()
    Dim params(0) As WmiParameter
    Dim target As New WmiParameterCollection
    target.Add(New WmiParameter)
    target.Add(New WmiParameter)
    target.CopyTo(params, 0)
  End Sub

  <TestMethod()>
  Public Sub CountTest()
    Dim target As New WmiParameterCollection
    Assert.AreEqual(0, target.Count)
    target.Add(New WmiParameter)
    Assert.AreEqual(1, target.Count)
    target.RemoveAt(0)
    Assert.AreEqual(0, target.Count)
  End Sub

  <TestMethod()>
  Public Sub GetEnumeratorTest()
    Dim en As IEnumerator
    Dim target As New WmiParameterCollection
    target.Add(New WmiParameter)
    en = target.GetEnumerator
    Assert.IsTrue(en.MoveNext)
    Assert.IsNotNull(en.Current)
  End Sub

  <TestMethod()>
  Public Sub IndexOf1Test()
    Dim param As New WmiParameter
    Dim target As New WmiParameterCollection

    Assert.AreEqual(-1, target.IndexOf(Nothing))
    Assert.AreEqual(-1, target.IndexOf(param))
    target.Add(param)
    Assert.AreEqual(0, target.IndexOf(param))
    target.Insert(0, New WmiParameter)
    Assert.AreEqual(1, target.IndexOf(param))
  End Sub

  <TestMethod()>
  Public Sub IndexOf2Test()
    Dim param As New WmiParameter("param", Nothing)
    Dim target As New WmiParameterCollection

    Assert.AreEqual(-1, target.IndexOf(String.Empty))
    Assert.AreEqual(-1, target.IndexOf("param"))
    target.Add(param)
    Assert.AreEqual(0, target.IndexOf("param"))
    target.Insert(0, New WmiParameter)
    Assert.AreEqual(1, target.IndexOf("param"))
  End Sub

  <TestMethod()>
  Public Sub IsFixedSizeTest()
    Dim target As New WmiParameterCollection
    Assert.IsFalse(target.IsFixedSize)
  End Sub

  <TestMethod()>
  Public Sub IsReadOnlyTest()
    Dim target As New WmiParameterCollection
    Assert.IsFalse(target.IsReadOnly)
  End Sub

  <TestMethod()>
  Public Sub IsSynchronizedTest()
    Dim target As New WmiParameterCollection
    Assert.IsFalse(target.IsSynchronized)
  End Sub

  <TestMethod()>
  Public Sub Item1Test()
    Dim param As New WmiParameter("name", Nothing)
    Dim target As New WmiParameterCollection
    target.Add(param)
    Assert.AreSame(param, target.Item(0))
    target.Item(0) = New WmiParameter
    Assert.AreNotSame(param, target.Item(0))
  End Sub

  <TestMethod(), ExpectedException(GetType(ArgumentOutOfRangeException))>
  Public Sub Item1ExceptionTest()
    Dim target As New WmiParameterCollection
    Assert.IsNull(target.Item(0))
  End Sub

  <TestMethod()>
  Public Sub Item2Test()
    Dim param As New WmiParameter("name", Nothing)
    Dim target As New WmiParameterCollection
    target.Add(param)
    Assert.AreSame(param, target.Item("name"))
    target.Item("name") = New WmiParameter("name2", Nothing)
    Assert.AreNotSame(param, target.Item("name2"))
  End Sub

  <TestMethod(), ExpectedException(GetType(ArgumentOutOfRangeException))>
  Public Sub Item2ExceptionTest()
    Dim target As New WmiParameterCollection
    Assert.IsNull(target.Item("name"))
  End Sub

  <TestMethod()>
  Public Sub RemoveTest()
    Dim param As New WmiParameter
    Dim target As New WmiParameterCollection
    target.Add(param)
    Assert.AreEqual(1, target.Count)
    target.Remove(param)
    Assert.AreEqual(0, target.Count)
  End Sub

  <TestMethod()>
  Public Sub RemoveAt1Test()
    Dim param As New WmiParameter
    Dim target As New WmiParameterCollection
    target.Add(param)
    Assert.AreEqual(1, target.Count)
    target.RemoveAt(0)
    Assert.AreEqual(0, target.Count)
  End Sub

  <TestMethod(), ExpectedException(GetType(ArgumentOutOfRangeException))>
  Public Sub RemoveAt1ExceptionTest()
    Dim target As New WmiParameterCollection
    target.RemoveAt(0)
  End Sub

  <TestMethod()>
  Public Sub RemoveAt2Test()
    Dim param As New WmiParameter("name", Nothing)
    Dim target As New WmiParameterCollection
    target.Add(param)
    Assert.AreEqual(1, target.Count)
    target.RemoveAt("name")
    Assert.AreEqual(0, target.Count)
  End Sub

  <TestMethod(), ExpectedException(GetType(ArgumentOutOfRangeException))>
  Public Sub RemoveAt2ExceptionTest()
    Dim target As New WmiParameterCollection
    target.RemoveAt("name")
  End Sub

  <TestMethod()>
  Public Sub SyncRootTest()
    Dim target As New WmiParameterCollection
    Assert.IsNotNull(target.SyncRoot)
    Assert.AreSame(target.SyncRoot, target.SyncRoot)
  End Sub
#End Region
End Class
